<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class UserLog extends Model
{
    public function change($change,$user_id,$currency_type='balance',$type=0,$remark='',$order_id=null){

        $userLog = new UserLog();
        if($change<0){
            $userLog->out = abs($change);
        }elseif ($change>0){
            $userLog->in = abs($change);
        }else{
            return true;
        }
        $userLog->user_id = $user_id;
        $userLog->currency_type = $currency_type;
        $userLog->type = $type;
        $userLog->remark = $remark;
        $userLog->order_id = $order_id;
        $r = $userLog->save();
        return $r?true:false;
    }

    public function user(){
        return $this->belongsTo(User::class);
    }
}
